 <!DOCTYPE html> 
<head>
<title>BITWA Petr Smid</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/css.css"/>   
 <style>
   .modra{background-color:red;}
   .oranz{background-color:orange;}
   .ruz {background-color:pink;}
   .cer{color:red;}
   table,td{border:1px solid black;}
</style> 
</head>
<body>        
<div id="global"><!-- Začátek Global -->
<h2>BITWA Petr Šmíd</h2>
<div id="hlavicka"><!-- Začátek hlavičky -->

</div><!-- Konec hlavičky -->
<div id="menu1"><!-- Začátek menu -->
<div id="banner1">
<h2>Další stránky</h2>


<a href="index.php">Domů</a>



</div>
</div>
<div id="obsah"> 
 
<?php
if (!empty($_GET)){
	$err = array();

if (!is_numeric($_GET['rok'])|| ($_GET['rok'])<=0){
		$err['rok'] = 'Špatné rok.';
	}
  if (!is_numeric($_GET['mes']) || $_GET['mes']<=0){
		$err['mes'] = 'Špatná mesic.';
	}
	    	
	if (!is_numeric($_GET['den']) || $_GET['den']<=0){
		$err['den'] = 'Špatná den.';
	}
	
}

$showForm = true;


if (isset($err)){
	if (!empty($err)){
		$showForm = true;
	
		foreach ($err as $current){
			echo "<div style='background-color: darkred;font-size:2em;'>  " . $current . "</div><br/>";
		}
	}
	else{
	    	
	    $pom = $_GET['rok']."-".$_GET['mes']."-".$_GET['den'];
	}
	$showForm = false;
}

?>



<?php
if ($showForm){
?>

<form action="vysledky.php" method="get">
	

	<br/><br/>

	<label for="rok"> Rok </label>
	<input type="text" id="rok" name="rok" value="<?php echo $_GET['rok'];?>">
		
	<br/><br/>
	<label for="mes"> Mesic </label>
	<input type="text" id="mes" name="mes" value="<?php echo $_GET['mes'];?>">

	<br/><br/>
	<label for="den"> Den </label>
	<input type="text" id="den" name="den" value="<?php echo $_GET['den'];?>">
   <br/><br/>

	<input type="submit" value="Hledat">
</form>

<?php
}else{ // else if ($showForm)


$con=mysql_connect("localhost", "smidpet5", "aez9okai");
// Check connection
if (!$con)
  {
  echo "Failed to connect to MySQL: " . mysql_connect_error();
  }

// Create database
mysql_select_db("smidpet5");

                                                                           
         $pom= strtotime($pom);
         $pom= date('Y-m-d',$pom);
          echo $pom;
$query ="SELECT Datum,BMI FROM BMII WHERE Datum >'$pom'";			
			                                                 
$mm = mysql_query($query);
if (!$mm) {
		    echo "Chyba: $query";
		    return false;
			}	
mysql_close();
echo "<table>";echo "<tr>";echo "<th>";echo "Datum";echo "</th>";echo "<th>";echo "BMI";echo "</th>";echo "</tr>";
	
			
while ($current=mysql_fetch_array($mm)){ 
			echo "<tr>";
			echo "<td>";
			echo $current["Datum"];
			echo "</td>";
			echo "<td>";
			echo $current["BMI"];
			echo "</td>";
			echo "</tr>";			
		}
		
		echo "</table>";        
}   


    
?>
</div><!-- Konec obsahu -->
</div> <!-- Konec Global -->
<div id="pata" style="text-align: center"> <!-- Začátek pata -->  
Úkol vypracoval: Petr Šmíd
</div><!-- Konec pata -->
        
</body>
</html>